import Vue from 'vue'

let _domMap = {}

function _checkpermission (el, binding) {
  const { arg, value } = binding
  if (value.indexOf(arg) < 0) {
    _domMap[arg] = el.parentNode
    el.parentNode.removeChild(el)
  } else {
    _domMap[arg] && _domMap[arg].appendChild(el)
  }
}

Vue.directive('permission', {
  inserted (el, binding) {
    _checkpermission(el, binding)
  },
  update (el, binding) {
    _checkpermission(el, binding)
  }
})